package com.bosssoft.trainee.nontax.hystrix;

import com.alibaba.fastjson.JSONObject;
import com.bosssoft.trainee.nontax.common.result.Result;
import com.bosssoft.trainee.nontax.entity.dto.TokenResult;
import com.bosssoft.trainee.nontax.entity.dto.UserInfo;
import com.bosssoft.trainee.nontax.entity.vo.UserVo;
import com.bosssoft.trainee.nontax.service.AuthorizeClientService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author Luo Wenlong
 * @date 2022-07-11 20:16
 * @description:服务降级
 * @version:
 */
@Component
public class AuthorizeClientServiceFallbackFactory implements FallbackFactory<AuthorizeClientService> {
    @Override
    public AuthorizeClientService create(Throwable throwable) {
        return new AuthorizeClientService() {
            @Override
            public Result<UserVo> getUserById(Integer id) {
                return Result.success(
                        UserVo.builder()
                                .userId(-1)
                                .tel("00000000000")
                                .deptName("系统繁忙")
                                .description("系统繁忙 请稍后再试")
                                .build());
            }

            @Override
            public Result<TokenResult> login(JSONObject jsonObject) {
                return Result.success(TokenResult.builder().token("fall back token, no use!").build());
            }

            @Override
            public Result<UserInfo> getInfo(String token) {
                return Result.success(UserInfo.builder().name("系统繁忙").introduction("系统繁忙，请稍后再试").build());
            }
        };
    }
}
